/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cheng.wildcard1.actions;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author james
 */
public class LoginRegistAction extends ActionSupport {

    // loginForm.jsp's request parameters;
    private String username;
    private String password;

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String regist() throws Exception {
        ActionContext.getContext().getSession().put("user", this.getUsername());
        this.addActionMessage("Congratulations, " + getUsername() + ", and you have already regist successful!");
        return SUCCESS;
    }

    public String login() throws Exception {
        if (getUsername().equals("Tom") && getPassword().equals("123")) {
            ActionContext.getContext().getSession().put("user", getUsername());
            this.addActionMessage("Welcome, " + getUsername() + ", and you have already Login successful!");
            return SUCCESS;
        }

        return ERROR;
    }

}
